package com.briup.cms.dao;

import com.briup.cms.bean.User;
import com.briup.cms.bean.extend.UserExtend;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Results(
            @Result(property = "roleId",  column = "role_id")

    )
    @Select("select * from cms_user where id=#{id}")
    List<User> selectInId(Long id);
    @Select("select * from cms_user")
    List<User> selectAll();
    @Insert("insert into cms_user values(null,#{username},#{password},#{telephone},#{gender},#{realName},#{photo},#{status},#{roleId})")
    void insert(User user);
    @Update("update cms_user set username=#{username},password=#{password},telephone=#{telephone},gender=#{gender},realName=#{realName},photo=#{photo},status=#{status},role_id=#{roleId} where id=#{id}")
    void update(User user);
    @Delete("delete from cms_user where id=#{id}")
    void delete (Long id);
    @Results({
            @Result(property = "roleId",  column = "role_id"),
            @Result(property = "roleName",  column = "role_name")
    })

    @Select("select u.*,r.name as role_name from cms_user u left join cms_role r on u.role_id = r.id")
    List<UserExtend> selectAllWithRole();
}
